package thread.chapter01;

/**
 * @author xinya
 * @version 1.0
 * @project javacore
 * @description 1.11.3TestThreadLocal
 * @date 2023/12/8 10:57:22
 */
public class TestThreadLocal {
    // 1.11.3 子线程不能使用父线程变量
    static ThreadLocal<String> threadLocal = new ThreadLocal<>();

    // 1.11.4 子线程能使用父线程变量
//    static ThreadLocal<String> threadLocal = new InheritableThreadLocal<>();

    public static void main(String[] args) {
        threadLocal.set("hello world");

        Thread threadOne = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("thread:" + threadLocal.get());
            }
        });

        threadOne.start();

        System.out.println("main:" + threadLocal.get());
    }

}
